// pages/personalCenter/mySelf/index.js
const config = require("../../../config")
const app = getApp()
const util = require("../../../utils/util.js")


Page({

  /**
   * 页面的初始数据
   */
  data: {
    bizSysName: "",
    companyName:"",
    userAvatar:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    util.postData(config.getUserUrl, {}).then(data => {
      data.body.data.photo = config.host + data.body.data.photo
      data.body.data.qrCode = config.host + data.body.data.qrCode
      app.globalData.bizUserData = data.body.data
      if (app.globalData.bizUserDataReadyCallBack){
        app.globalData.bizUserDataReadyCallBack(data.body.data)
      }
      this.setData({ bizSysName: data.body.data.name,userAvatar:data.body.data.photo, companyName: data.body.data.company.name})
    })

  },
  refreshUser: function () {
    if (app.globalData.bizUserData){
      this.setData({ bizSysName: app.globalData.bizUserData.name, companyName: app.globalData.bizUserData.company.name, userAvatar: data.photo})
    }else{
      app.globalData.bizUserDataReadyCallBack = (data)=>{
        this.setData({ bizSysName: data.name, companyName: data.company.name })
      }
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.refreshUser()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },
  showUserData: function () {
    wx.navigateTo({
      url: '../personalInfo/personalInfo'
    })
  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },
  logout: function () {
    let that = this;
    util.getData(config.UnBindUrl + ";JSESSIONID=" + wx.getStorageSync("JSESSIONID"), { openID: "testopenid" }).then(data => {
      app.globalData.bizUserInfo = {};
      that.setData({ bizSysName: "", companyName:"" })
      wx.reLaunch({
        url: '../../demoIndex/index',
      })
    })
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})